home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 May / Disc 2 / PCU0503CD2.iso / BitFax_BitWare / BitWarePro / Simply / fclass1.scp < prev    next >
Encoding:
Text File  |  2001-09-05  |  32.1 KB  |  1,300 lines

  1. //-----------------------------------------------------------------------
  2. // ext vars
  3. // @szATCmd  - str (LPSTR)  @c1TxB_FRH = 3000  @c1RxB_FTH = 3000
  4. // @szCID    - str            @c1TxB_FRHFTH = 0  @c1RxB_FTHFRH = 0
  5. // @szDCS    - str            @c1TxB_FTH = 3000  @c1RxB_FRH = 3000
  6. // @szDIS    - str            @c1TxB_FTHFTM = 0  @c1RxB_FRHFRM = 0
  7. // @szDCC    - str            @c1TxB_FTM = 3000  @c1RxB_FRM = 3000
  8. // @szHNG    - str            @c1TxB_FTMFRH = 0  @c1RxB_FRMFTH = 0
  9. // @szNSF    - str            @c1TxB_FRH2 =3000  @c1RxB_FTH2 =3000
  10. // @lpszRespBuff - str        @c1TxB_FRHFTM = 0  @c1RxB_FTHFRM = 0
  11. // @lPageCnt    - long        @c1TxC_FTM = 3000  @c1RxC_FRM = 3000
  12. // @lPageTotal  - long        @c1TxD_DataFTH =0  @c1RxD_DataFRH =0
  13. // @lSizeForNSF - long        @c1TxD_FTH = 3000  @c1RxD_FRH = 3000
  14. // @ComIO                     @c1TxD_FTHFRH = 0  @c1RxD_FRHFTH = 0
  15. // @GlStr1                    @c1TxD_FRH = 3000  @c1RxD_FTH = 3000
  16. // @GlStr2                    @c1TxE_FRHFTH = 0  @c1RxE_FTHFRH = 0
  17. // @RespBuffer                @c1TxE_FTH = 3000  @c1RxE_FRH = 3000
  18. //---------------------------------------------------------------------
  19. //---------------------------------------------------------------------
  20. // ext functions
  21. //fSetBaudRate(DWORD lpParam, DWORD Baud, DWORD dwN1, DWORD dwN2);
  22. //fWaitResponse(DWORD lpParam, DWORD lpBuf, DWORD lTimeOut, DWORD dwN1);
  23. //fSendATCmd(DWORD lpParam, DWORD lpBuf, DWORD dwN1, DWORD dwN2);
  24. //fSendDLE_ETX(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  25. //fSleep(DWORD lTime, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  26. //fFlushRxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  27. //fFlushTxQueue(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  28. //fSendOneChar(DWORD lpParam, DWORD dwCh, DWORD dwN1, DWORD dwN2);
  29. //fWaitOneChar(DWORD lpParam, DWORD lpResultChar, DWORD lTimeOut, DWORD dwN1);
  30. //fSetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  31. //fResetDTR(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  32. //fSetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  33. //fResetRTS(DWORD lpParam, DWORD dwN1, DWORD dwN2, DWORD dwN3);
  34. //fSetMisc(DWORD lpParam, DWORD nParity, DWORD nDataBits, DWORD nStopBits);
  35. //fSetMiscMore(DWORD lpParam, DWORD bDTRDSR, DWORD bRTSCTS, DWORD bXONXOFF);
  36. //fHardFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
  37. //fSoftFlowControl(DWORD lpParam, DWORD Type, DWORD dwN1, DWORD dwN2);
  38. //fSkipSpaceStrStr(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
  39. //fTxFirstResponseError(DWORD s1, DWORD s2, DWORD dwN1, DWORD dwN2);
  40. //
  41. //   For fHardFlowControl:
  42. //     param1 - 0000X0YY   X  - Cts flow control
  43. //                         YY : 00 - RTS DISABLE
  44. //                         YY : 01 - RTS ENABLE
  45. //                         YY : 10 - RTS HANDSHAKE
  46. //                         YY : 11 - RTS TOGGLE
  47. //     For fSoftFlowControl:
  48. //     param1 - 00000XXX   000(0) - No flowcontrol
  49. //                         001(1) - Send flowcontrol
  50. //                         002(2) - Recv flowcontrol
  51. //                         004(4) - Both send and recv flowcontrol
  52. // 
  53. //-------------------------------------------------------------------------
  54. //
  55. //
  56. // This is the script file for Class1.
  57. //
  58. //trace
  59. popup
  60. declare STRING %szStr1, %szStr2;
  61. declare STRING %szStr3, %szStr4;
  62. declare STRING %szPass1, %szPass2;
  63. declare STRING %szPass3, %szPass4;
  64. declare STRING %szMsg1;
  65. declare long   %lRes0;
  66. declare long   %lRes1;
  67. declare long   %lRes2;
  68. declare long   %lTemp0;
  69. declare long   %lTemp1;
  70. declare long   %lGRes0;
  71. declare long   %lGRes1;
  72. declare long   %lMsg1;
  73. declare long   %bSendFRH;
  74. declare long   %lAccTrain;
  75. declare long   %AlreadySendFrame;
  76. declare long   %nRetryCount;
  77. declare long   %bBadRxTrain;
  78. declare char   %XON;
  79. declare STRING %szNULL;
  80. declare STRING %szFrameContent;
  81.  
  82. //----------------------------------------------------------------------
  83. // SubSendCmdWaitResp
  84. //----------------------------------------------------------------------
  85. sub  SubSendCmdWaitResp(STRING #szCmd, STRING #szResp, long #lWaitTime)
  86. declare long %lRes;
  87. declare STRING %szCheckAT;
  88. declare long %lLimit;
  89.  
  90.         %lLimit = 0
  91.     %szCheckAT = "AT"
  92.     %lRes = fSkipSpaceStrStr(%szCheckAT, #szCmd)
  93.     if (%lRes = 0)
  94.        {
  95.        %lRes = 0
  96.        goto SendCmd1
  97.        }
  98.  
  99.     %lRes = fSendATCmd(@ComIO, #szCmd)
  100.     if (%lRes!=0)
  101.        {
  102.        %lRes = 101
  103.        goto SendCmd1
  104.        }
  105.  
  106. :SendCmd0
  107.     %lRes = fWaitResponse(@ComIO, #lWaitTime)
  108.     if (%lRes != 0)
  109.        {
  110.        %lRes = 101
  111.        goto SendCmd1
  112.        }
  113.  
  114.     %lRes = fSkipSpaceStrStr(#szResp, @RespBuffer)
  115.         if (%lRes != 0)
  116.            {
  117.            %lRes = 0
  118.            goto SendCmd1
  119.            }
  120.  
  121.         // some response but doesnt match, retry agian if necessary
  122.         %lLimit = %lLimit+1
  123.         if (%lLimit < 3)
  124.            goto SendCmd0
  125.  
  126.         // Not match...
  127.         %lRes = 101
  128.  
  129. :SendCmd1
  130.     %lGRes0 = %lRes
  131. endsub
  132.  
  133. //----------------------------------------------------------------------
  134. //----------------------------------------------------------------------
  135. sub  SubWaitOK(long #lWaitTime)
  136. declare long   %lRes;
  137. declare STRING %szStrOK;
  138. declare long   %lLimit;
  139.  
  140.     %lLimit = 0
  141.  
  142.  
  143. :SubWOK0
  144.     %lRes = fWaitResponse(@ComIO, #lWaitTime)
  145.     if (%lRes != 0)
  146.        {
  147.        %lRes = 101
  148.        goto SubWOK1
  149.        }
  150.  
  151.     %szStrOK = "OK"
  152.     %lRes = fSkipSpaceStrStr(%szStrOK, @RespBuffer)
  153.     if (%lRes != 0)
  154.        {
  155.        %lRes = 0
  156.        goto SubWOK1
  157.        }    
  158.  
  159.     //
  160.     // %lRes = 0 means respbuffer and str doesnt match, try again if necessary
  161.     //
  162.     %lLimit = %lLimit+1
  163.     if (%lLimit < 3)
  164.        goto SubWOK0
  165.  
  166.     // error return 101 here
  167.     %lRes = 101
  168.  
  169. :SubWOK1
  170.     %lGRes0 = %lRes
  171. endsub
  172.  
  173. //----------------------------------------------------------------------
  174. //----------------------------------------------------------------------
  175. sub SubSendLastFrame(long #lWaitTime)
  176. declare long %lRes;
  177. declare STRING %szFTH;
  178.  
  179.     fFlushRxQueue(@ComIO)
  180.     %szFTH = "AT+FTH=3"
  181.     %lRes = fSendATCmd(@ComIO, %szFTH)
  182.     if (%lRes!=0)
  183.        {
  184.        %lRes = 101
  185.        goto SubSLF0
  186.        }
  187.  
  188.     %lRes = fWaitResponse(@ComIO, #lWaitTime)
  189.     if (%lRes != 0)
  190.        {
  191.        %lRes = 101
  192.        goto SubSLF0
  193.        }
  194.  
  195.     %szFTH = "CONNECT"
  196.     %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
  197.     if (%lRes = 0)          // the response is not CONNECT
  198.            {
  199.        %lRes = 101
  200.        goto SubSLF0
  201.        }
  202.  
  203.     fC1SendLastFrame(@FClass1)
  204.     %lRes = 0
  205.  
  206. :SubSLF0
  207.     %lGRes0 = %lRes
  208. endsub
  209.  
  210.  
  211. //----------------------------------------------------------------------
  212. // SubSendFrame(STRING #FrameContent, 
  213. //   long #lWaitTime, 
  214. //   long #lMode       [for lMode = 1 : wait for connect,  
  215. //                                  2 : no wait for connect]
  216. //   )
  217. //----------------------------------------------------------------------
  218. sub SubSendFrame(STRING #FrameContent, long #lWaitTime, long #lMode)
  219. declare long %lRes;
  220. declare STRING %szFTH;
  221.     %AlreadySendFrame = 1
  222.  
  223.     if (#lMode = 1)         // wait for connect
  224.        goto SubSF0
  225.  
  226.     if (#lMode = 2)         // dont even wait for connect
  227.        goto SubSF1
  228.  
  229.     fFlushRxQueue(@ComIO)
  230.     %szFTH = "AT+FTH=3"
  231.     %lRes = fSendATCmd(@ComIO, %szFTH)
  232.     if (%lRes!=0)
  233.        {
  234.        %lRes = 101
  235.        goto SubSF2
  236.        }
  237.  
  238. :SubSF0
  239.     %lRes = fWaitResponse(@ComIO, #lWaitTime)
  240.     if (%lRes != 0)
  241.        {
  242.        %lRes = 101
  243.        goto SubSF2
  244.        }
  245.  
  246.     %szFTH = "CONNECT"
  247.     %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
  248.     if (%lRes = 0)          // the response is not CONNECT
  249.        %lRes = 101
  250.  
  251. :SubSF1
  252.     fC1SendFrame(@FClass1, #FrameContent)
  253.     %lRes = 0
  254.  
  255. :SubSF2
  256.     %lGRes0 = %lRes
  257. endsub
  258.  
  259. //----------------------------------------------------------------------
  260. // Use lGRes0 as return
  261. // Send FRH if necessary
  262. // if bSendFRH = 0 -> send AT+FRH and wait for connect
  263. //               1 -> just wait data
  264. //
  265. // return 0 : OK
  266. //        1 : Error
  267. //        2 : Retry Overlimited
  268. //----------------------------------------------------------------------
  269. sub  SubWaitFrame(long #bSendFRH, long #lWaitTime)
  270. declare long   %lRes;
  271. declare STRING %szStrs;
  272.     if (#bSendFRH = 1) goto SubWFrame8
  273.  
  274.     fSleep(30)
  275.         %szStrs = "AT+FRH=3"
  276.     %lRes = fSendATCmd(@ComIO, %szStrs)
  277.     if (%lRes = 0)
  278.        goto SubWFrame3
  279.  
  280.     %lRes = 1
  281.     goto SubWFrame9
  282.  
  283. //        if (%lRes!=0)
  284. //           {
  285. //           %lRes = 1
  286. //           goto SubWFrame9
  287. //           }
  288. //
  289.  
  290. :SubWFrame3
  291.     %lRes = fWaitResponse(@ComIO, #lWaitTime)
  292.     if (%lRes = 0)
  293.        goto SubWFrame4
  294.        
  295.     %lRes = 1
  296.     goto SubWFrame9
  297.  
  298. //        if (%lRes != 0)
  299. //           {
  300. //           %lRes = 1
  301. //           goto SubWFrame9
  302. //           }
  303. //
  304.  
  305. :SubWFrame4
  306.     %szStrs = "CONNECT"
  307.     %lRes = fSkipSpaceStrStr(%szStrs, @RespBuffer)
  308.     if (%lRes != 0)
  309.        goto SubWFrame8
  310.  
  311.     %lRes = 1
  312.     goto SubWFrame9
  313.  
  314. //
  315. //        if (%lRes = 0)
  316. //           goto SubWFrame9
  317. //
  318. :SubWFrame8
  319.     %lRes = fC1RecvFrame(@FClass1, #lWaitTime)
  320.  
  321. :SubWFrame9
  322.     %lGRes0 = %lRes
  323. endsub
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330. //----------------------------------------------------------------------
  331. //----------------------------------------------------------------------
  332. sub SubSendFrameDCS(STRING #FrameContent, long #lWaitTime, long #lMode)
  333. declare long %lRes;
  334. declare STRING %szFTH;
  335.  
  336.     if (#lMode = 1)         // wait for connect
  337.        goto SubSFDCS0
  338.  
  339.     if (#lMode = 2)         // dont even wait for connect
  340.        goto SubSFDCS1
  341.  
  342.     fFlushRxQueue(@ComIO)
  343.  
  344.     %szFTH = "AT+FTH=3"
  345.     %lRes = fSendATCmd(@ComIO, %szFTH)
  346.     if (%lRes!=0)
  347.        {
  348.        %lRes = 101
  349.        goto SubSFDCS2
  350.        }
  351.  
  352. :SubSFDCS0
  353.     %lRes = fWaitResponse(@ComIO, #lWaitTime)
  354.     if (%lRes != 0)
  355.        {
  356.        %lRes = 101
  357.        goto SubSFDCS2
  358.        }
  359.  
  360.     %szFTH = "CONNECT"
  361.     %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
  362.     if (%lRes = 0)          // the response is not CONNECT
  363.        %lRes = 101
  364.  
  365. :SubSFDCS1
  366.     fC1SendFrame(@FClass1, @c1CommonDCS)
  367.     %lRes = 0
  368.  
  369. :SubSFDCS2
  370.     %lGRes0 = %lRes
  371. endsub
  372.  
  373.  
  374.  
  375. //----------------------------------------------------------------------
  376. //----------------------------------------------------------------------
  377. sub SubSendFrameDIS(STRING #FrameContent, long #lWaitTime, long #lMode)
  378. declare long %lRes;
  379. declare STRING %szFTH;
  380.  
  381.     if (#lMode = 1)         // wait for connect
  382.        goto SubSFDIS0
  383.  
  384.     if (#lMode = 2)         // dont even wait for connect
  385.        goto SubSFDIS1
  386.  
  387.     fFlushRxQueue(@ComIO)
  388.  
  389.     %szFTH = "AT+FTH=3"
  390.     %lRes = fSendATCmd(@ComIO, %szFTH)
  391.     if (%lRes!=0)
  392.        {
  393.        %lRes = 101
  394.        goto SubSFDIS2
  395.        }
  396.  
  397. :SubSFDIS0
  398.     %lRes = fWaitResponse(@ComIO, #lWaitTime)
  399.     if (%lRes != 0)
  400.        {
  401.        %lRes = 101
  402.        goto SubSFDIS2
  403.        }
  404.  
  405.     %szFTH = "CONNECT"
  406.     %lRes = fSkipSpaceStrStr(%szFTH, @RespBuffer)
  407.     if (%lRes = 0)          // the response is not CONNECT
  408.        %lRes = 101
  409.  
  410. :SubSFDIS1
  411.     fC1SendFrame(@FClass1, @c1LocalDIS)
  412.     %lRes = 0
  413.  
  414. :SubSFDIS2
  415.     %lGRes0 = %lRes
  416. endsub
  417.  
  418.  
  419. //----------------------------------------------------------------------
  420. // class1 timing
  421. //----------------------------------------------------------------------
  422. sub  SubC1TimingPara
  423.     @c1TxB_FRH = 3000        // For rx frame time limit
  424.     @c1TxB_FRHFTH = 0        // After rx frame and before tx frame interval
  425.     @c1TxB_FTH = 3000        // For tx frame interval
  426.     @c1TxB_FTHFTM = 0        // After tx frame and tx training interval
  427.     @c1TxB_FTM = 3000        // AT+FTM training time limit
  428.     @c1TxB_FTMFRH = 0        // After tx training and rx frame interval
  429.     @c1TxB_FRH2 =3000        // For rx frame time limit (frame CFR, FTT)
  430.     @c1TxB_FRHFTM = 0        // After rx frame and tx data interval
  431.     @c1TxC_FTM = 3000        // AT+FTM time limit
  432.     @c1TxD_DataFTH =300        // PhaseC and PhaseD AT+FTH interval
  433.     @c1TxD_FTH = 3000        // Tx frame time limit
  434.     @c1TxD_FTHFRH = 0        // After tx frame and before rx frame interval
  435.     @c1TxD_FRH = 3000        // Rx frame time limit
  436.     @c1TxE_FRHFTH = 0        // After rx frame and before tx frame interval
  437.     @c1TxE_FTH = 3000        // Tx frame time limit
  438.  
  439.     @c1RxB_FTH = 3000        // For tx frame time limit                      
  440.     @c1RxB_FTHFRH = 0        // After tx frame and before rx frame interval  
  441.     @c1RxB_FRH = 3000        // For rx frame interval                        
  442.     @c1RxB_FRHFRM = 0        // After rx frame and rx training interval      
  443.     @c1RxB_FRM = 3000        // AT+FRM training time limit                   
  444.     @c1RxB_FRMFTH = 0        // After rx training and tx frame interval      
  445.     @c1RxB_FTH2 =3000        // For tx frame time limit (frame CFR, FTT)     
  446.     @c1RxB_FTHFRM = 0        // After tx frame and rx data interval          
  447.     @c1RxC_FRM = 3000        // AT+FRM time limit                            
  448.     @c1RxD_DataFRH =0        // PhaseC and PhaseD AT+FRH interval            
  449.     @c1RxD_FRH = 3000        // Rx frame time limit                          
  450.     @c1RxD_FRHFTH = 500        // After rx frame and before tx frame interval  
  451.     @c1RxD_FTH = 3000        // Tx frame time limit                          
  452.     @c1RxE_FTHFRH = 0        // After tx frame and before rx frame interval  
  453.     @c1RxE_FRH = 3000        // Rx frame time limit                          
  454. endsub
  455.  
  456. //----------------------------------------------------------------------
  457. // For Dialing number
  458. //----------------------------------------------------------------------
  459. :TX_DIAL
  460.     call SubC1TimingPara
  461.     fFlushRxQueue(@ComIO)
  462.     fSleep(1500)
  463.     
  464.     fSendATCmd(@ComIO, @szATCmd)
  465.     fSleep(1000)
  466. //  fFlushRxQueue(@ComIO)
  467.     %bSendFRH = 1
  468.     %AlreadySendFrame = 0
  469.     %nRetryCount = 0
  470.     exit(0)
  471.  
  472.  
  473. //----------------------------------------------------------------------
  474. // For TX initialization part 1
  475. //
  476. //   and for fHardFlowControl(@ComIO, 9) - CTS on / RTS on
  477. //----------------------------------------------------------------------
  478. :TX_INIT1
  479.     call SubC1TimingPara
  480.     %AlreadySendFrame = 0
  481.     %nRetryCount = 0
  482.  
  483.     fHardFlowControl(@ComIO, 9)
  484. //  fSoftFlowControl(@ComIO, 0)
  485.  
  486.     fSetBaudRate(@ComIO, 19200)
  487.     fFlushRxQueue(@ComIO)
  488.     fFlushTxQueue(@ComIO)
  489.     @szATCmd = "ATZ"
  490.     fSendATCmd(@ComIO, @szATCmd)
  491.     fSleep(5000)
  492.     fFlushRxQueue(@ComIO)
  493.     @szATCmd = "ATS0=0M0E0"
  494.     fSendATCmd(@ComIO, @szATCmd)
  495.     fSleep(1000)
  496.     fFlushRxQueue(@ComIO)
  497.  
  498.     call SubSendCmdWaitResp("ATE0", "OK", 3000)
  499.     fSleep(150)
  500.  
  501.     call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
  502.     fSleep(150)
  503.  
  504.     call SubSendCmdWaitResp("ATE0V1&C1&D2", "OK", 3000)
  505.     fSleep(150)
  506.  
  507.     %lGRes1 = %lGRes0
  508.     call SubSendCmdWaitResp("AT&K3", "OK", 3000)
  509. //  call SubSendCmdWaitResp("AT&K4", "OK", 3000)
  510.     %lGRes0 = %lGRes1
  511.     fSleep(150)
  512.  
  513.     %bSendFRH = 0
  514.     exit (%lGRes0)
  515.  
  516. :TX_INIT2
  517.     fSetBaudRate(@ComIO, 19200)
  518.     call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
  519.     if (%lGRes0 = 0)
  520.         exit (0)
  521.     
  522.     exit (%lGRes0)
  523.  
  524. :TX_INIT3
  525.     exit (0)
  526.  
  527. //
  528. // You can do all kind of thing here...
  529. :TX_INIT4
  530.     exit (0)
  531.  
  532.  
  533. //----------------------------------------------------------------------
  534. // Now we go to Tx phase B - Wait for OK and send AT+FDR
  535. //
  536. // ??? I dont know whether we need to wait for FCON or not...
  537. //----------------------------------------------------------------------
  538. :TXPH_B_START
  539. //  fSoftFlowControl(@ComIO, 0);
  540.     %szStr3 = "This is in TXPH_B_START"
  541.     %lRes0 = fPrintMsg(%szStr3)
  542.  
  543. :TXPH_B_START1
  544.     %lRes0 = fWaitResponse(@ComIO, 5000) 
  545.     if (%lRes0 != 0)
  546.     exit (4)
  547.  
  548.     // Check to see if any error happens. eg: No dial tone, busy...
  549.     %lRes0 = fTxFirstResponseError(@RespBuffer)
  550.     if (%lRes0 != 0)
  551.        {
  552.        exit (%lRes0)
  553.        }
  554.  
  555.     // Yes, sth is the buffer, we need to compare it.  It must be
  556.     // CONNECT.
  557.     %szStr3 = "CONNECT"
  558.     %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  559.     if (%lRes0 = 0)
  560.        exit (1)
  561.     exit (0)
  562.  
  563.  
  564. //----------------------------------------------------------------
  565. //----------------------------------------------------------------
  566. :TXPH_C_START
  567.     fSoftFlowControl(@ComIO, 1)
  568.     exit (0)
  569.  
  570.  
  571. //----------------------------------------------------------------
  572. //----------------------------------------------------------------
  573. :FAXMAIN
  574. :FAXMAIN_WAITFRAME
  575. // 0:good, 1:retry, 2:quit  resulted in lGRes0
  576. //    fSoftFlowControl(@ComIO, 0)
  577.     call SubWaitFrame(%bSendFRH, 4500)
  578.     %bSendFRH = 0
  579.  
  580.     if (%lGRes0 = 7)        // to speed thing up
  581.        {
  582.        %nRetryCount = 0
  583.        goto SIG_DCS
  584.        }
  585.  
  586.     if (%lGRes0 = 0)
  587.        {
  588.        %nRetryCount = 0
  589.        goto FAXMAIN_NEXTFRAME
  590.        }
  591.  
  592. // dont get good frame    
  593.     %lRes0 = %nRetryCount + 1 
  594.     %nRetryCount = %lRes0
  595.     if (%nRetryCount > 6)
  596.        exit (2)
  597.  
  598.     fSleep(1000)
  599.     if (%AlreadySendFrame = 0)
  600.        {
  601.        call SubSendCmdWaitResp("AT", "OK", 2000)
  602.        }
  603.     else
  604.        {
  605.        call SubSendCmdWaitResp("AT", "OK", 2000)
  606.        call SubSendLastFrame(3000)
  607.        call SubWaitOK(3000)
  608.        }
  609.     goto FAXMAIN 
  610.  
  611. //---------------------------------------------------------
  612. // At this point, we receive a frame or some frames.
  613. //---------------------------------------------------------
  614. :FAXMAIN_NEXTFRAME
  615.     %lRes2 = fC1NextFrame(@FClass1, %szFrameContent)
  616. :FAXMAIN_NXTFME
  617.     if (%lRes2 = 7)  goto SIG_DCS        // to speed thing up
  618.     if (%lRes2 = 1)  goto SIG_DIS
  619.     if (%lRes2 = 2)  goto SIG_CSI  
  620.     if (%lRes2 = 3)  goto SIG_NSF  
  621.     if (%lRes2 = 4)  goto SIG_DTC
  622.     if (%lRes2 = 5)  goto SIG_CIG
  623.     if (%lRes2 = 6)  goto SIG_NSC
  624.     if (%lRes2 = 7)  goto SIG_DCS
  625.     if (%lRes2 = 8)  goto SIG_TSI
  626.     if (%lRes2 = 9)  goto SIG_NSS
  627.     if (%lRes2 = 10) goto SIG_CFR
  628.     if (%lRes2 = 11) goto SIG_FTT
  629.     if (%lRes2 = 12) goto SIG_EOM
  630.     if (%lRes2 = 13) goto SIG_MPS
  631.     if (%lRes2 = 14) goto SIG_EOP
  632.     if (%lRes2 = 15) goto SIG_PRIEOM
  633.     if (%lRes2 = 16) goto SIG_PRIMPS
  634.     if (%lRes2 = 17) goto SIG_PRIEOP
  635.     if (%lRes2 = 18) goto SIG_MCF
  636.     if (%lRes2 = 19) goto SIG_RTP
  637.     if (%lRes2 = 20) goto SIG_PIP
  638.     if (%lRes2 = 21) goto SIG_RTN
  639.     if (%lRes2 = 22) goto SIG_PIN
  640.     if (%lRes2 = 23) goto SIG_DCN
  641.     if (%lRes2 = 24) goto SIG_CRP
  642.     if (%lRes2 = 25) goto SIG_FCD
  643.     if (%lRes2 = 26) goto SIG_RCP
  644.     if (%lRes2 = 27) goto SIG_PPS
  645.     if (%lRes2 = 28) goto SIG_PPR
  646.     if (%lRes2 = 29) goto SIG_CTC
  647.     if (%lRes2 = 30) goto SIG_CTR
  648.     if (%lRes2 = 31) goto SIG_EOR
  649.     if (%lRes2 = 32) goto SIG_ERR
  650.     if (%lRes2 = 33) goto SIG_RR 
  651.     if (%lRes2 = 34) goto SIG_RNR
  652.     if (%lRes2 = 35) goto SIG_FDM
  653.     if (%lRes2 = 36) goto SIG_NUL
  654.  
  655.    
  656. //-------------------- for DIS 
  657. :SIG_NSF 
  658.     goto FAXMAIN_NEXTFRAME
  659.  
  660. :SIG_CSI
  661.     fC1StoreRemoteID(@FClass1, %szFrameContent)
  662.     goto FAXMAIN_NEXTFRAME
  663.  
  664. :SIG_DIS
  665.     fC1CopyFrame(@FClass1, @c1RemoteDIS, %szFrameContent)
  666.     fC1MakeUpDCS(@FClass1)
  667.  
  668. :SND_DCS
  669.     call SubSendFrame(@c1TSI, 3000, 0)
  670.     call SubSendFrameDCS(@c1CommonDCS, 3000, 1)
  671.     call SubWaitOK(3000)
  672.     fC1GetSpeedString(@FClass1, %szStr2, 1)
  673.     %szStr3 = "AT+FTM="
  674.     %szStr4 = %szStr3 + %szStr2
  675.     call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
  676.  
  677. //    fSoftFlowControl(@ComIO, 1)
  678.     fC1TxTrain(@FClass1)
  679. //    fSoftFlowControl(@ComIO, 0)
  680.  
  681.     call SubWaitOK(3000)
  682.     goto FAXMAIN_WAITFRAME
  683.  
  684.  
  685. //-------------------- for DTC 
  686. :SIG_NSC 
  687.     goto FAXMAIN_NEXTFRAME
  688. :SIG_CIG
  689.     fC1StoreRemoteID(@FClass1, %szFrameContent)
  690.     goto FAXMAIN_NEXTFRAME
  691. :SIG_DTC
  692.     call SubSendFrame(@c1CSI, 3000, 0)
  693.     call SubSendFrame(@c1LocalDIS, 3000, 1)
  694.     call SubWaitOK(3000)
  695.     goto FAXMAIN_WAITFRAME
  696.  
  697. //--------------------  for DCS 
  698. :SIG_NSS
  699.     goto FAXMAIN_NEXTFRAME
  700. :SIG_TSI
  701.     fC1StoreRemoteID(@FClass1, %szFrameContent)
  702.     goto FAXMAIN_NEXTFRAME
  703. :SIG_DCS
  704. //    call SubSendCmdWaitResp("AT+FRM=96", "CONNECT", 5500)
  705. //*
  706. //*   fC1CopyFrame(@FClass1, @c1CommonDCS, %szFrameContent)
  707. //*   fC1GetSpeedString(@FClass1, %szStr2, 1)
  708. //---Testing...
  709. //    if (%bBadRxTrain = 1)
  710. //        exit (1)
  711. //    else
  712. //        exit (0)
  713.  
  714.  
  715.  
  716. :RXTRAIN_START
  717.     %lAccTrain = 0
  718. //  %szStr3 = "This is in RX_TRAINING..."
  719. //  %lRes0 = fPrintMsg(%szStr3)
  720.  
  721. :RXTRAIN_START_1
  722.     %szStr3 = "AT+FRM="
  723.     %szStr2 = @c1TrainSpeedStr
  724.     %szStr4 = %szStr3 + %szStr2
  725. //  fFlushRxQueue(@ComIO)
  726.     call SubSendCmdWaitResp(%szStr4, "CONNECT", 5500)
  727.     if (%lGRes0 = 0)
  728.        {
  729.        %szStr3 = "Get the Connect message now..."
  730.        %lRes0 = fPrintMsg(%szStr3)
  731.        %lGRes1 = fC1RxTrain(@FClass1, 3000)
  732.        goto RXTRAIN_RESULT
  733.        }
  734.  
  735.     %lAccTrain = %lAccTrain + 1
  736.     %szStr3 = "Didnt Get the Connect message YET..."
  737.     %lRes0 = fPrintMsg(%szStr3)
  738.     call SubSendCmdWaitResp("AT", "OK", 1000)
  739.     if (%lAccTrain > 6)
  740.        %lGRes1 = 1
  741.     else
  742.        goto RXTRAIN_START_1
  743.  
  744.     %szStr3 = "go to RXTRAINRESULT..."
  745.     %lRes0 = fPrintMsg(%szStr3)
  746.     goto RXTRAIN_RESULT
  747.     // Get rid of OK or CONNECT message
  748.     //--------------------------------------------------------
  749. :RXTRAIN_1
  750.     %lRes2 = fWaitResponse(@ComIO, 300)
  751.     if (%lRes2 != 0)
  752.        {
  753.        // Sth wrong with the training.
  754.        %lGRes1 = 1
  755.        goto RXTRAIN_RESULT
  756.        }
  757.  
  758.     %szStr4 = "OK"
  759.     %lRes2 = fSkipSpaceStrStr(%szStr4, @RespBuffer)
  760.     if (%lRes2 != 0)
  761.        goto RXTRAIN_RESULT
  762.  
  763.     %szStr4 = "NO CARRIER"
  764.     %lRes2 = fSkipSpaceStrStr(%szStr4, @RespBuffer)
  765.     if (%lRes2 != 0)
  766.        goto RXTRAIN_RESULT
  767.     goto RXTRAIN_1
  768.     
  769.     //--------------------------------------------------------
  770.     // Above is for Get rid of OK or CONNECT message
  771.  
  772. :RXTRAIN_RESULT
  773.     %szStr3 = "This is in RX_TRAINING RESULT"
  774.     %lRes0 = fPrintMsg(%szStr3)
  775.     fFlushRxQueue(@ComIO)
  776.     if (%lGRes1 = 0)
  777.        {
  778.        %bBadRxTrain = 0
  779.        call SubSendFrame(@c1CFR, 3000, 0)
  780.        call SubWaitOK(3000)
  781.  
  782.        // Send AT+FRM=XX to receive data...
  783.        %szStr3 = "AT+FRM="
  784.        %szStr2 = @c1DataSpeedStr
  785.        %szStr4 = %szStr3 + %szStr2
  786.        fFlushRxQueue(@ComIO)
  787.        call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
  788.        exit (0)
  789.        }
  790.     else
  791.        {
  792.        %bBadRxTrain = 1
  793.        call SubSendFrame(@c1FTT, 3000, 0)
  794.        call SubWaitOK(3000)
  795.        goto FAXMAIN_WAITFRAME
  796.        }
  797.  
  798.  
  799. //--------------------  for training
  800. :SIG_FTT
  801.     %lRes0 = fC1StepDown(@FClass1)
  802.     if (%lRes0 != 0)
  803.        exit (%lRes0)
  804.     goto SND_DCS
  805.  
  806.  
  807. // For class1 - We got SIG_CFR already.  Send AT+FTM now
  808. :TXTRAIN_START   
  809.     fC1GetSpeedString(@FClass1, %szStr2, 0)
  810.     %szStr3 = "AT+FTM="
  811.     %szStr4 = %szStr3 + %szStr2
  812.     call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
  813.     exit (0)
  814.  
  815. :TXTRAIN_START_PHD   
  816.     fC1GetSpeedString(@FClass1, %szStr2, 1)
  817.     %szStr3 = "AT+FTM="
  818.     %szStr4 = %szStr3 + %szStr2
  819.     call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
  820.     exit (1)
  821.  
  822. :SIG_CFR
  823. //    fSoftFlowControl(@ComIO, 1)
  824.     exit (0)
  825.  
  826.  
  827. // for phase D
  828. :SIG_MPS
  829.     %szStr3 = "GetMPS"
  830.     %lRes0 = fPrintMsg(%szStr3)
  831.     call SubSendFrame(@c1MCF, 3000, 0)
  832.     call SubWaitOK(3000)
  833.  
  834.     %szStr3 = "AT+FRM="
  835.     %szStr4 = %szStr3 + %szStr2
  836.     fFlushRxQueue(@ComIO)
  837.     call SubSendCmdWaitResp(%szStr4, "CONNECT", 3000)
  838.     exit (1)
  839.  
  840. :SIG_EOM
  841.     call SubSendFrame(@c1MCF, 3000, 0)
  842.     call SubWaitOK(3000)
  843.     goto FAXMAIN_WAITFRAME
  844.     
  845. :SIG_EOP
  846.     %szStr3 = "GetEOP"
  847.     %lRes0 = fPrintMsg(%szStr3)
  848.     call SubSendFrame(@c1MCF, 3000, 0)
  849.     call SubWaitOK(3000)
  850.     goto FAXMAIN_WAITFRAME
  851.     
  852.  
  853. //--------------------  for phase D with interrupt (which we dont support)
  854. :SIG_PRIEOM
  855. :SIG_PRIEOP
  856. :SIG_PRIMPS 
  857.     goto FAXMAIN_WAITFRAME
  858.  
  859. //--------------------  for phase D 
  860. :SIG_MCF
  861.     if (@lPageCnt >= @lPageTotal)
  862.        goto SND_DCN
  863.     else
  864.        goto TXTRAIN_START_PHD
  865.  
  866. :SIG_RTN
  867. :SIG_RTP 
  868.     %lRes0 = fC1StepDown(@FClass1)
  869.     if (%lRes0 != 0)
  870.        exit (%lRes0)
  871.     goto SND_DCS
  872.  
  873.  
  874. //--------------------  disconnect
  875. :SIG_DCN
  876.     goto FAXMAIN_DISCONNECT
  877.   
  878. :SND_DCN
  879.     call SubSendFrame(@c1DCN, 3000, 0)
  880.     call SubWaitOK(3000)
  881.     goto FAXMAIN_DISCONNECT
  882.  
  883.  
  884. //--------------------  repeat last signal
  885. :SIG_CRP
  886.     call SubSendCmdWaitResp("AT", "OK", 500)
  887.     call SubSendLastFrame(3000)
  888.     call SubWaitOK(3000)
  889.     goto FAXMAIN_DISCONNECT
  890.  
  891.  
  892. //--------------------  To Send DIS after ATA
  893. //Remember use 2 as the input parameter to SubSendFrame
  894. //
  895. :SND_DIS
  896.     call SubSendFrame(@c1CSI, 3000, 2)
  897.     call SubSendFrameDIS(@c1LocalDIS, 3000, 1)
  898.     call SubWaitOK(3000)
  899.     goto FAXMAIN_WAITFRAME
  900.  
  901.     
  902. :SND_MPS
  903.     call SubSendFrame(@c1MPS, 3000, 0)
  904.     call SubWaitOK(3000)
  905.     goto FAXMAIN_WAITFRAME
  906.  
  907. :SND_EOP
  908.     call SubSendFrame(@c1EOP, 3000, 0)
  909.     call SubWaitOK(3000)
  910.     goto FAXMAIN_WAITFRAME
  911.  
  912. :SND_EOM
  913.     call SubSendFrame(@c1EOM, 3000, 0)
  914.     call SubWaitOK(3000)
  915.     goto FAXMAIN_WAITFRAME
  916.  
  917.  
  918.  
  919. //
  920. // The below signals are for ECM
  921. //
  922. :SIG_CTC
  923.     exit (0)
  924. :SIG_CTR
  925.     exit (0)
  926. :SIG_EOR 
  927.     exit (0)
  928. :SIG_ERR 
  929.     exit (0)
  930. :SIG_FCD 
  931.     exit (0)
  932. :SIG_PIN 
  933.     exit (0)
  934. :SIG_PIP 
  935.     exit (0)
  936. :SIG_PIS
  937.     exit (0)
  938. :SIG_PPS
  939.     exit (0)
  940. :SIG_PPR 
  941.     exit (0)
  942. :SIG_RCP
  943.     exit (0)
  944. :SIG_RNR
  945.     exit (0)
  946. :SIG_RR
  947.     exit (0)
  948. :SIG_NUL
  949.     exit (0)
  950.  
  951. :TXPH_D_START
  952. //    %szStr3 = "This is in TXPH_D_START"
  953. //    %lRes0 = fPrintMsg(%szStr3)
  954.  
  955.     fSendOneChar(@ComIO, 0)
  956.     fSendOneChar(@ComIO, 0)
  957.     fSendOneChar(@ComIO, 8)
  958.     fSendOneChar(@ComIO, 128)
  959.  
  960.     fSendOneChar(@ComIO, 0)
  961.     fSendOneChar(@ComIO, 8)
  962.     fSendOneChar(@ComIO, 128)
  963.  
  964.     fSendOneChar(@ComIO, 0)
  965.     fSendOneChar(@ComIO, 8)
  966.     fSendOneChar(@ComIO, 128)
  967.     fSendDLE_ETX(@ComIO)
  968.  
  969.  
  970. :TXPH_D0
  971.      %lRes0 = fWaitResponse(@ComIO, 30000)
  972.      // NO response error (3)
  973.      if (%lRes0 != 0)
  974.     exit (3)
  975.  
  976.      %szStr3 = "OK"
  977.      %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  978.      if (%lRes0 = 0)
  979.     goto TXPH_D0
  980.  
  981.     %lRes0 = @lPageCnt + 1
  982.     @lPageCnt = %lRes0
  983.     exit (0)
  984.  
  985.  
  986.  
  987. //----------------------------------------------------------------------
  988. //  Disconnecting the line
  989. //----------------------------------------------------------------------
  990. :FAXMAIN_DISCONNECT
  991. :ABORT1
  992. :TX_DISC1
  993. :RX_DISC1
  994.     %AlreadySendFrame = 0
  995.     %nRetryCount = 0
  996.     %bBadRxTrain = 0
  997.  
  998.     %szStr3 = "This is in DISC1"
  999.     %lRes0 = fPrintMsg(%szStr3)
  1000.  
  1001.     %bSendFRH = 0
  1002.     fFlushRxQueue(@ComIO)
  1003. //  fSendDLE_ETX(@ComIO)
  1004.     %szStr3 = "AT"
  1005.     fSendATCmd(@ComIO, %szStr3)
  1006.     fSleep(1000)
  1007.     %szStr3 = "AT"
  1008.     fSendATCmd(@ComIO, %szStr3)
  1009.     fSleep(1000)
  1010.  
  1011.     fFlushRxQueue(@ComIO)
  1012.     fFlushTxQueue(@ComIO)
  1013.     %szStr3 = "ATH0"
  1014.     call SubSendCmdWaitResp(%szStr3, "OK", 2000)
  1015.  
  1016.  
  1017.     fFlushRxQueue(@ComIO)
  1018.     fFlushTxQueue(@ComIO)
  1019.     %szStr3 = "AT+FCLASS=0"
  1020.     call SubSendCmdWaitResp(%szStr3, "OK", 2000)
  1021.     fSetBaudRate(@ComIO, 2400)
  1022.     fSleep(500)
  1023.  
  1024. //  %szStr3 = "ATZ"
  1025.     %szStr3 = "AT"
  1026.     call SubSendCmdWaitResp(%szStr3, "OK", 3000)
  1027.     fFlushRxQueue(@ComIO)
  1028.  
  1029.  
  1030. //  fSendATCmd(@ComIO, @szATCmd)  // comes from szTxQuitString
  1031.     fSleep(500)
  1032.     fResetDTR(@ComIO)
  1033.     fSleep(1000)
  1034.     fSetDTR(@ComIO)
  1035.     fFlushRxQueue(@ComIO)
  1036.     fFlushTxQueue(@ComIO)
  1037.     exit (0)
  1038.  
  1039. :ABORT2
  1040. :TX_DISC2
  1041. :RX_DISC2
  1042.     fFlushRxQueue(@ComIO)
  1043.     fFlushTxQueue(@ComIO)
  1044. //  fSendATCmd(@ComIO, @szATCmd)
  1045.     fSleep(1000)
  1046.     fFlushRxQueue(@ComIO)
  1047.     fFlushTxQueue(@ComIO)
  1048.     exit (0)
  1049.  
  1050. :TX_DISC3
  1051. :RX_DISC3
  1052.     exit (0)
  1053.  
  1054. :TX_DISC4
  1055. :RX_DISC4
  1056.     exit (0)
  1057.  
  1058. //----------------------------------------------------------------------
  1059. // The following are for RX fax
  1060. //----------------------------------------------------------------------
  1061. //----------------------------------------------------------------------
  1062. //  For HardFlowControl - use 11 means CTS on/RTS toggle.
  1063. //----------------------------------------------------------------------
  1064. :RX_INIT1
  1065.     call SubC1TimingPara
  1066.     %AlreadySendFrame = 0
  1067.     %nRetryCount = 0
  1068.     %bBadRxTrain = 0
  1069.  
  1070.     fHardFlowControl(@ComIO, 9)
  1071.     fSoftFlowControl(@ComIO, 0)
  1072.     fSetBaudRate(@ComIO, 19200)
  1073.     fFlushRxQueue(@ComIO)
  1074.     fFlushTxQueue(@ComIO)
  1075.     @szATCmd = "ATS0=0M0E0"
  1076.     fSendATCmd(@ComIO, @szATCmd)
  1077.     fSleep(1000)                      // 100
  1078.     fFlushRxQueue(@ComIO)
  1079.     @szATCmd = "ATS0=0M0E0"
  1080.     fSendATCmd(@ComIO, @szATCmd)
  1081.     fSleep(1000)                      // 100
  1082.     fFlushRxQueue(@ComIO)
  1083.     call SubSendCmdWaitResp("AT&FE0", "OK", 3000)
  1084.     fSleep(1000)
  1085.  
  1086.     call SubSendCmdWaitResp("ATS0=0", "OK", 3000)
  1087.     fSleep(150)
  1088.  
  1089.     call SubSendCmdWaitResp("ATE0V1&C1&D2X4", "OK", 3000)
  1090.     fSleep(150)
  1091.  
  1092.     %lGRes1 = %lGRes0
  1093.     call SubSendCmdWaitResp("AT&K3", "OK", 3000)
  1094. //  call SubSendCmdWaitResp("AT&K4", "OK", 3000)
  1095.     %lGRes0 = %lGRes1
  1096.     fSleep(150)
  1097.  
  1098.     %bSendFRH = 0
  1099.     exit (%lGRes0)
  1100.  
  1101. :RX_INIT2
  1102. //  call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
  1103. //  if (%lGRes0 = 0)
  1104. //      fSetBaudRate(@ComIO, 19200)
  1105.   call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
  1106.   fSleep(500)
  1107.   fSetBaudRate(@ComIO, 19200)
  1108.   exit (%lGRes0)
  1109.  
  1110. :RX_INIT3
  1111.     exit (0)
  1112.  
  1113. :RX_INIT4
  1114.     exit (0)
  1115.  
  1116.  
  1117. //----------------------------------------------------------------------
  1118. // RX_WAITCALL
  1119. //
  1120. // Wait for 3 seconds for RING signal
  1121. //----------------------------------------------------------------------
  1122. :RX_WAITCALL
  1123.     %szStr3 = "This is in RX_WAITCALL (C2)"
  1124.     %lRes0 = fPrintMsg(%szStr3)
  1125.  
  1126.     fFlushRxQueue(@ComIO)
  1127.     fFlushTxQueue(@ComIO)
  1128.     %lRes0 = fWaitResponse(@ComIO, 3000) 
  1129.         if (%lRes0 != 0)
  1130.             exit (%lRes0)
  1131.  
  1132.     // Something is in the buffer, check if this is RING signal
  1133.     %szStr3 = "RING"
  1134.     %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  1135.     if (%lRes0 != 0)
  1136.        exit (0)
  1137.     else
  1138.        exit (1)
  1139.  
  1140.  
  1141. //----------------------------------------------------------------------
  1142. // RX_ANSWERCALL
  1143. //----------------------------------------------------------------------
  1144. :RX_ANSWERCALL
  1145.     call SubC1TimingPara
  1146.  
  1147.     %szStr3 = "This is in RX_ANSWERCALL"
  1148.     %lRes0 = fPrintMsg(%szStr3)
  1149.  
  1150.     %AlreadySendFrame = 0
  1151.     %nRetryCount = 0
  1152.     %bBadRxTrain = 0
  1153.  
  1154.     @lPageTotal = 0
  1155.     @lPageCnt = 0
  1156.  
  1157.     fFlushRxQueue(@ComIO)
  1158.     fFlushTxQueue(@ComIO)
  1159.  
  1160.     call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
  1161.     if (%lGRes0 = 0)
  1162.        fSetBaudRate(@ComIO, 19200)
  1163.     fSleep(250)
  1164.  
  1165.     fFlushRxQueue(@ComIO)
  1166.     @szATCmd = "ATA"
  1167.     fSendATCmd(@ComIO, @szATCmd)
  1168.     exit (0)
  1169.  
  1170. //----------------------------------------------------------------------
  1171. // RX_PH_B_START
  1172. //----------------------------------------------------------------------
  1173. :RXPH_B_START
  1174.     %szStr3 = "This is in RXPH_B_START"
  1175.     %lRes0 = fPrintMsg(%szStr3)
  1176.  
  1177.     %lRes0 = fWaitResponse(@ComIO, 30000) 
  1178.     if (%lRes0 != 0)
  1179.     exit (1)
  1180.  
  1181.     // Check to see if any error happens. eg: No dial tone, busy...
  1182.     %lRes0 = fTxFirstResponseError(@RespBuffer)
  1183.     if (%lRes0 != 0)
  1184.        {
  1185.        exit (%lRes0)
  1186.        }
  1187.  
  1188.     // Yes, sth is the buffer, we need to compare it
  1189.     %szStr3 = "CONNECT"
  1190.     %lRes0 = fSkipSpaceStrStr(%szStr3, @RespBuffer)
  1191.     if (%lRes0 != 0)
  1192.         exit (0)
  1193.     else
  1194.         exit (1)
  1195.  
  1196.  
  1197. :RXPH_D_START
  1198.     %lRes0 = @lPageTotal + 1
  1199.     @lPageTotal = %lRes0
  1200.  
  1201.     %lRes0 = @lPageCnt + 1
  1202.     @lPageCnt = %lRes0
  1203.  
  1204.     exit (0)
  1205.  
  1206.  
  1207. //----------------------------------------------------------------------
  1208. //----------------------------------------------------------------------
  1209. :TAPIRX_INIT1
  1210.     call SubC1TimingPara
  1211.     %szStr3 = "This is in TAPIRX_INIT"
  1212.     %lRes0 = fPrintMsg(%szStr3)
  1213.  
  1214.     %AlreadySendFrame = 0
  1215.     %nRetryCount = 0
  1216.     %bBadRxTrain = 0
  1217.  
  1218.     @lPageTotal = 0
  1219.     @lPageCnt = 0
  1220.  
  1221.     fSendOneChar(@ComIO, 16)
  1222.     fSendOneChar(@ComIO, 3)
  1223.     fSendOneChar(@ComIO, 16)
  1224.     fSendOneChar(@ComIO, 3)
  1225.  
  1226.     fSendOneChar(@ComIO, 16)
  1227.     fSendOneChar(@ComIO, 24)
  1228.     call SubSendCmdWaitResp("AT", "OK", 1000)
  1229.     fSleep(150)
  1230.  
  1231.     call SubSendCmdWaitResp("ATE0V1&D2", "OK", 1000)
  1232.     fSleep(150)
  1233.  
  1234.     fHardFlowControl(@ComIO, 9)
  1235.     fSoftFlowControl(@ComIO, 0)
  1236.     fSetBaudRate(@ComIO, 19200)
  1237.     fFlushRxQueue(@ComIO)
  1238.     fFlushTxQueue(@ComIO)
  1239.  
  1240.     call SubSendCmdWaitResp("AT+FCLASS=0", "OK", 1000)
  1241.     fSleep(1000)
  1242. //  call SubSendCmdWaitResp("AT#BDR=0", "OK", 1000)
  1243. //  fSleep(150)
  1244. //  call SubSendCmdWaitResp("AT&FE0", "OK", 1000)
  1245. //  fSleep(1000)
  1246.  
  1247.     call SubSendCmdWaitResp("ATE0V1&C1&D2X4", "OK", 1000)
  1248.     fSleep(300)
  1249.     call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 1000)
  1250.     fSetBaudRate(@ComIO, 19200)
  1251.     fSleep(500)
  1252.     fFlushRxQueue(@ComIO)
  1253.     fFlushTxQueue(@ComIO)
  1254.  
  1255.  
  1256.     @szATCmd = "ATA"
  1257.     fSendATCmd(@ComIO, @szATCmd)
  1258.     exit (0)
  1259.  
  1260. :TAPIRX_INIT2
  1261.     exit (0)
  1262.  
  1263. :TAPIRX_INIT3
  1264.     exit (0)
  1265.  
  1266. :TAPIRX_INIT4
  1267.     exit (0)
  1268.  
  1269.  
  1270. //----------------------------------------------------------------------
  1271. //----------------------------------------------------------------------
  1272. :TAPITX_INIT1
  1273.     call SubC1TimingPara
  1274.     %AlreadySendFrame = 0
  1275.     %nRetryCount = 0
  1276.  
  1277.     fHardFlowControl(@ComIO, 9)
  1278.     fFlushRxQueue(@ComIO)
  1279.     call SubSendCmdWaitResp("ATE0V1&C1&D2", "OK", 3000)
  1280.     fSleep(150)
  1281.  
  1282.     call SubSendCmdWaitResp("AT+FCLASS=1", "OK", 3000)
  1283.     fSleep(150)
  1284.  
  1285.  
  1286.     fSetBaudRate(@ComIO, 19200)
  1287.     @szATCmd = "ATD"
  1288.     fSendATCmd(@ComIO, @szATCmd)
  1289.     exit (0)
  1290.  
  1291. :TAPITX_INIT2
  1292.     exit (0)
  1293.  
  1294. :TAPITX_INIT3
  1295.     exit (0)
  1296.  
  1297. :TAPITX_INIT4
  1298.     exit (0)
  1299.  
  1300.